import javax.swing.*;
import java.awt.event.ActionListener;

/**
 * Creat with IntelliJ IDEA
 * Description:
 * User:WZW
 * Date:2021-12-14
 * Time:23:47
 */
public class timer{
    public Timer t;
    public int time = 2;//20秒倒计时

    public void count(ActionListener listener) {
        t = new Timer(time*1000,listener);
        t.setRepeats(false);
        t.start();
    }

    public String timeRemain(){
        while (time > 0) {
            time--;
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return ("还剩" + time + "秒");
    }

}
